/**
 * 处理地图注入
 */
import * as echarts from "echarts";
import ObtainData from "./obtainData";
interface IObtainDataParams {
  name: string;
  origin: string;
  [key: string]: any;
}
class MapRegister extends ObtainData {
  _echartsMapRegister(name: string, data: any) {
    !echarts.getMap(name) && echarts.registerMap(name, data);
  }
  async _handleRegister(config: IObtainDataParams) {
    const { name, origin } = config;
    let geoJson;
    switch (origin) {
      case "static":
      case "upload":
        geoJson = config.data;
        break;
      case "request":
        geoJson = await this.getRequestData((config as any));
        break;
    }
    geoJson && this._echartsMapRegister(name, geoJson);
  }
  registerMap(data: Array<any>) {
    data.forEach(async item => {
      if (item.name && item.origin) {
        await this._handleRegister(item);
      }
    })
  }
}
export default new MapRegister();